package com.cloudcentral.controller;

import com.cloudcentral.entity.dto.RoleDTO;
import com.cloudcentral.entity.query.RoleQuery;
import com.cloudcentral.entity.vo.RoleVO;
import com.cloudcentral.service.RoleService;
import com.cloudcentral.util.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 系统角色表 前端控制器
 * </p>
 *
 * @author Administrator
 * @since 2023-10-27
 */
@Slf4j
@RestController
@RequestMapping("/role")
@Tag(name = "角色管理")
public class RoleController extends BaseController {
  private final RoleService roleService;

  @Autowired
  public RoleController(RoleService roleService) {
    this.roleService = roleService;
  }

  @PostMapping("/submit")
  @Operation(summary = "提交")
  public Result<Boolean> submit(RoleDTO dto) throws Exception {
    return Result.ok(roleService.submit(dto));
  }

  @DeleteMapping("/delete")
  @Operation(summary = "删除")
  public Result<Boolean> delete(Long id) {
    return Result.ok(roleService.delete(id));
  }

  @GetMapping("/select")
  @Operation(summary = "查询")
  public Result<RoleVO> select(Long id) {
    return Result.ok(roleService.queryRoleVOById(id));
  }

  @GetMapping("/list")
  @Operation(summary = "列表")
  public Result<List<RoleVO>> list(RoleQuery query) {
    return Result.ok(roleService.listRoleVO(query));
  }
}
